﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using System.Web.Security;
using Microsoft.SharePoint.Administration;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using NCS.IConnect.ApplicationContexts;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.IncorruptArchives.JianWuDuCha
{
    public partial class JianWuDuChaUserControl : UserControl
    {
        string currentAccount = SPContext.Current.Web.CurrentUser.Name;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (currentAccount != "admin")
                {
                    this.tbSearch.Visible = false;
                    using (IncorruptProxy proxy = new IncorruptProxy())
                    {
                        IncorruptDataSet.T_JianWuDuChaDataTable loadDT = proxy.GetJianWuDuCha(0, string.Empty, null, null, currentAccount);
                        this.gvBC.DataSource = loadDT;
                        this.gvBC.DataBind();
                    }
                }
                else
                {
                    this.tbSearch.Visible = true;
                }
            }
        }

        protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
        {
            string number = this.txtNumber.Text;
            string name = this.txtName.Text;


            DateTime? start = null;
            DateTime? end = null;

            if (!dtDateFrom.IsDateEmpty)
                start = this.dtDateFrom.SelectedDate;

            if (!dtDateTo.IsDateEmpty)
                end = this.dtDateTo.SelectedDate;

            using (IncorruptProxy proxy = new IncorruptProxy())
            {
                IncorruptDataSet.T_JianWuDuChaDataTable searchDT = proxy.GetJianWuDuCha(0, number, start, end, name);
                this.gvBC.DataSource = searchDT;
                this.gvBC.DataBind();
            }
        }

        protected void imgCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("JianWuDuCha.aspx");
        }

        protected void gvBC_DataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // load date format
                Label lblDate = (Label)e.Row.Cells[1].FindControl("lblDate");

                string dateString = lblDate.Text;
                DateTime dateTime = DateTime.Parse(dateString);
                lblDate.Text = dateTime.ToString(JCYConstant.Date_Format_CN);
            }

        }
    }
}
